package com.newdjk.newdoctor.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.drawable.Drawable;

import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.Gson;
import com.newdjk.newdoctor.R;
import com.newdjk.newdoctor.entity.CityEntity;
import com.newdjk.newdoctor.entity.PatientListEntity;
import com.newdjk.newdoctor.utils.GlideUtils;
import com.newdjk.newdoctor.view.CircleImageView;


import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.text.SimpleDateFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PatientAdapter extends BaseQuickAdapter<PatientListEntity.ReturnDataBean, BaseViewHolder> {

    List<PatientListEntity.ReturnDataBean> mPaintList;

    public PatientAdapter(@Nullable List<PatientListEntity.ReturnDataBean> data) {
        super(R.layout.patient_item, data);
        mPaintList = data;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, PatientListEntity.ReturnDataBean returnDataBean) {

        String nameLetter = returnDataBean.getNameLetter();
        String lastName="";
        String cureentName="";
        if (helper.getAdapterPosition() == 0) {
            if (TextUtils.isEmpty(nameLetter)) {
                helper.setText(R.id.alpha, "#");

            } else {
                helper.setText(R.id.alpha, nameLetter.substring(0, 1));
            }
            helper.setVisible(R.id.alpha, true);
        } else {
             cureentName = mPaintList.get(helper.getAdapterPosition()).getNameLetter();

             lastName= mPaintList.get(helper.getAdapterPosition() - 1).getNameLetter();

            if (TextUtils.isEmpty(cureentName)) {
                helper.setGone(R.id.alpha, true);
            } else {
                if (TextUtils.isEmpty(lastName)) {
                    helper.setGone(R.id.alpha, false);
                } else {
                    if (cureentName.substring(0, 1).equals(lastName.substring(0, 1))) {
                        helper.setGone(R.id.alpha, true);
                    } else {
                        helper.setGone(R.id.alpha, false);
                    }
                }
                if (TextUtils.isEmpty(nameLetter)) {
                    helper.setText(R.id.alpha, "未知字母");
                } else {
                    helper.setText(R.id.alpha, nameLetter.substring(0, 1));
                }

            }

        }


        String disease = returnDataBean.getDisease();
        if (disease != null && !disease.equals("")) {
            helper.setText(R.id.tv_diseaselabel, disease);
        } else {
            helper.setText(R.id.tv_diseaselabel, "暂无标签");
        }

        String name = returnDataBean.getPatientName();

        helper.setText(R.id.patient_name, TextUtils.isEmpty(name) ? "未知姓名" : name);

        CircleImageView avatar = helper.getView(R.id.avatar);
        GlideUtils.loadPatientImage(returnDataBean.getPaPicturePath(), avatar);

        int sexType = returnDataBean.getPatientSex();
        if (sexType == 1) {
            helper.setText(R.id.sex, "男");
        } else if (sexType == 2) {
            helper.setText(R.id.sex, "女");
        } else if (sexType == 3) {
            helper.setText(R.id.sex, "未确定");
        }
        helper.setText(R.id.age, TextUtils.isEmpty(returnDataBean.getAge()) ? "未知年龄" : returnDataBean.getAge());

    }


    public void setDataList(List<PatientListEntity.ReturnDataBean> mPaintList) {
        this.mPaintList = mPaintList;
    }
}
